var express=require('express');
var app = express();


var getline = require('./routes/getLine');
var getsummary = require('./routes/getSummary');
var picUpload = require('./routes/picUpload');
var write = require('./routes/writeArtical');
var bodyParser = require('body-parser');


app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  if(req.method=="OPTIONS") res.send(200);/*让options请求快速返回*/
  else  next();
});

app.use('/getLine',getline);
app.use('/getSummary',getsummary);


var multer  = require('multer');

app.use(multer({ dest: './router/files'}))
app.use('/picUpload',picUpload);

app.use(bodyParser.urlencoded({ extended: false }))
app.use('/write',write);

var server = app.listen(8080, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})